package org.lql.algo.codecrush.hot100.binaryTree;

import org.lql.algo.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: liangqinglong
 * @date: 2025-09-07 17:38
 * @description: 94. 二叉树的中序遍历 <a href="https://leetcode.cn/problems/binary-tree-inorder-traversal/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class InorderTraversal {

	public List<Integer> preorderTraversal(TreeNode root) {
		List<Integer> ans = new ArrayList<>();
		if (root == null) {
			return ans;
		}
		preorder(root, ans);
		return ans;
	}

	public void preorder(TreeNode root, List<Integer> ans) {
		if (root == null) {
			return;
		}
		preorder(root.left, ans);
		ans.add(root.val);
		preorder(root.right, ans);
	}
}
